
/*************************************************
 * TopNavigationBar Controller
 ************************************************/
function TopNavigationBarCtrl($scope, $rootScope, $location, 
                              Login, LoginValidate, GetUsersByProjects, sharedService) {
  
  $scope.selectedIndex = 0

  $rootScope.config = {}

  /**
   * Menu Item Click event
   */
  $scope.itemClick = function(index){
    $scope.selectedIndex = index;
  }



  $scope.validateLogin = function () {
     // Login
    LoginValidate.get(function(data) {
        $rootScope.config.user = data.result;
        console.log ("user: ", data.user)
        $scope.getAllUsers();
        //sharedService.prepForBroadcast("hello man", 99);
    })


  }
  $scope.validateLogin();
    


  $scope.getAllUsers = function () {
    
    GetUsersByProjects.get(function(data) {
        $rootScope.config.users = data.result
        //sharedService.prepForBroadcast("hello man", 99);
    })
  }


  
}

 TopNavigationBarCtrl.$inject = ['$scope', '$rootScope', '$location', 
                                 'Login', 'LoginValidate', 'GetUsersByProjects', 'mySharedService'];

/*************************************************
 * Book Main Controller
 ************************************************/
function BookMainCtrl($scope) {

  $scope.panelTitle = "MY BOOKS";


  $scope.books = [
    {url: "http://www.google.com",  title: "EaselJS Started"},
    {url: "http://www.apple.com",  title: "Android Development"},
    {url: "http://www.adobe.com",  title: "AngularJS"},
  ];


  /**
   * Remove Book
   */
  $scope.removeBook = function (index, item) {

    console.log ("item", item)
    $scope.books.splice(index,1);      

  }

  /**
   * Invoked when a new book is saved
   */
  $scope.$on('urlSaveEvent', function(event, args) {

     $scope.books.push({ title: args.title, 
                               url: args.url })

  });

}




/*************************************************
 * ADD BOOK Controller
 ************************************************/
function AddPanelCtrl($scope) {

  /**
   * SAVE
   */
  $scope.save = function () {
      
      console.log ("book.title:", $scope.book.title)
     // console.log ("bookUrl:", $scope.book.url)
      // Dispatch Save event 
      $scope.$emit('urlSaveEvent',
      {
       title: $scope.book.title,
       url:   $scope.book.url
      });

      // Reset Values
      $scope.book.title = "";
      $scope.book.url = "";
  }


}



